<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="WTTWi2XnJ5">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Josefin Sans:300,300italic,400,400italic,700,700italic|Lobster:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lclong.top","root":"/","scheme":"Gemini","version":"7.7.1","exturl":true,"sidebar":{"position":"left","display":"post","padding":20,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Mybatis Plusmybatis plus 在 mybatis 基础上没有改变其本身，并做了增强。 官方提供在Github的mybatis-plus-samples 参考：MP官网">
<meta property="og:type" content="article">
<meta property="og:title" content="Mybatis Plus的使用">
<meta property="og:url" content="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/index.html">
<meta property="og:site_name" content="Zlatanlong&#39;s T-blog">
<meta property="og:description" content="Mybatis Plusmybatis plus 在 mybatis 基础上没有改变其本身，并做了增强。 官方提供在Github的mybatis-plus-samples 参考：MP官网">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/relationship-with-mybatis.png">
<meta property="og:image" content="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/mybatis-plus-framework.jpg">
<meta property="article:published_time" content="2020-03-17T05:48:28.000Z">
<meta property="article:modified_time" content="2020-03-30T15:56:20.000Z">
<meta property="article:author" content="Zlatanlong">
<meta property="article:tag" content="Spring Boot">
<meta property="article:tag" content="Mybatis Plus">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/relationship-with-mybatis.png">

<link rel="canonical" href="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>Mybatis Plus的使用 | Zlatanlong's T-blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zlatanlong's T-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">Lakers is Championship!</h1>
      
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">38</span></a>

  </li>
        <li class="menu-item menu-item-aboutme">

    <a href="/aboutme/" rel="section"><i class="fa fa-fw fa-user"></i>博主</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Zlatanlong">
      <meta itemprop="description" content="生活就像巧克力🍫">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zlatanlong's T-blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          Mybatis Plus的使用
        </h2>

        <div class="post-meta">
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-03-17 13:48:28" itemprop="dateCreated datePublished" datetime="2020-03-17T13:48:28+08:00">2020-03-17</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-03-30 23:56:20" itemprop="dateModified" datetime="2020-03-30T23:56:20+08:00">2020-03-30</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/" itemprop="url" rel="index">
                    <span itemprop="name">Java</span>
                  </a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Java/Mybatis/" itemprop="url" rel="index">
                    <span itemprop="name">Mybatis</span>
                  </a>
                </span>
            </span>

          
            <span id="/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/" class="post-meta-item leancloud_visitors" data-flag-title="Mybatis Plus的使用" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">评论次数：</span>
    
    <a title="valine" href="/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>8 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="Mybatis-Plus"><a href="#Mybatis-Plus" class="headerlink" title="Mybatis Plus"></a>Mybatis Plus</h1><p>mybatis plus 在 mybatis 基础上没有改变其本身，并做了增强。</p>
<p><span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2Jhb21pZG91L215YmF0aXMtcGx1cy1zYW1wbGVz" title="https://github.com/baomidou/mybatis-plus-samples">官方提供在Github的mybatis-plus-samples<i class="fa fa-external-link"></i></span></p>
<p><span class="exturl" data-url="aHR0cHM6Ly9tcC5iYW9taWRvdS5jb20v" title="https://mp.baomidou.com/">参考：MP官网<i class="fa fa-external-link"></i></span></p>
<p><img src="/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/relationship-with-mybatis.png" alt="官方宣传图"></p>
<a id="more"></a>

<h2 id="基本结构："><a href="#基本结构：" class="headerlink" title="基本结构："></a>基本结构：</h2><p>其中core是mybatis，</p>
<p><img src="/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/mybatis-plus-framework.jpg" alt></p>
<h2 id="配置基本："><a href="#配置基本：" class="headerlink" title="配置基本："></a>配置基本：</h2><h3 id="导入依赖："><a href="#导入依赖：" class="headerlink" title="导入依赖："></a>导入依赖：</h3><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.baomidou<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>mybatis-plus-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>版本<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h3 id="application-yml"><a href="#application-yml" class="headerlink" title="application.yml"></a>application.yml</h3><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">datasource:</span></span><br><span class="line">    <span class="attr">username:</span> <span class="string">root</span></span><br><span class="line">    <span class="attr">password:</span> <span class="string">lcl123</span></span><br><span class="line">    <span class="attr">url:</span> <span class="string">jdbc:mysql://localhost:3306/mybatis?useSSl=false&amp;serverTimeZone=UTC&amp;characterEncoding=utf-8</span></span><br><span class="line">    <span class="attr">driver-class-name:</span> <span class="string">com.mysql.cj.jdbc.Driver</span></span><br></pre></td></tr></table></figure>

<h3 id="添加扫描路径："><a href="#添加扫描路径：" class="headerlink" title="添加扫描路径："></a>添加扫描路径：</h3><ol>
<li>在 Spring Boot 启动类中添加 <code>@MapperScan</code> 注解，扫描 Mapper 文件夹：</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SpringBootApplication</span></span><br><span class="line"><span class="meta">@MapperScan</span>(<span class="string">"com.baomidou.mybatisplus.samples.quickstart.mapper"</span>)</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Application</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">        SpringApplication.run(QuickStartApplication<span class="class">.<span class="keyword">class</span>, <span class="title">args</span>)</span>;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>或者在每个Mapper类上加上<code>@Mapper</code>注解</li>
</ol>
<h2 id="基本方法："><a href="#基本方法：" class="headerlink" title="基本方法："></a>基本方法：</h2><h3 id="用户实体："><a href="#用户实体：" class="headerlink" title="用户实体："></a>用户实体：</h3><p>编写实体类 <code>User.java</code>（此处使用了 <span class="exturl" data-url="aHR0cHM6Ly93d3cucHJvamVjdGxvbWJvay5vcmcv" title="https://www.projectlombok.org/">Lombok<i class="fa fa-external-link"></i></span> 简化代码）</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">User</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> Long id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Integer age;</span><br><span class="line">    <span class="keyword">private</span> String email;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="编写Mapper类，并集成BaseMapper"><a href="#编写Mapper类，并集成BaseMapper" class="headerlink" title="编写Mapper类，并集成BaseMapper"></a>编写Mapper类，并集成BaseMapper</h3><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">UserMapper</span> <span class="keyword">extends</span> <span class="title">BaseMapper</span>&lt;<span class="title">User</span>&gt; </span>&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="常用注解"><a href="#常用注解" class="headerlink" title="常用注解"></a>常用注解</h2><h3 id="TableName"><a href="#TableName" class="headerlink" title="@TableName"></a>@TableName</h3><ul>
<li>描述：表名注解</li>
</ul>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>必须指定</th>
<th>默认值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>value</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>表名</td>
</tr>
<tr>
<td>schema</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>schema</td>
</tr>
<tr>
<td>keepGlobalPrefix</td>
<td>boolean</td>
<td>否</td>
<td>false</td>
<td>是否保持使用全局的 tablePrefix 的值(如果设置了全局 tablePrefix 且自行设置了 value 的值)</td>
</tr>
<tr>
<td>resultMap</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>xml 中 resultMap 的 id</td>
</tr>
<tr>
<td>autoResultMap</td>
<td>boolean</td>
<td>否</td>
<td>false</td>
<td>是否自动构建 resultMap 并使用(如果设置 resultMap 则不会进行 resultMap 的自动构建并注入)</td>
</tr>
</tbody></table>
<h3 id="TableId"><a href="#TableId" class="headerlink" title="@TableId"></a>@TableId</h3><ul>
<li>描述：主键注解</li>
</ul>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>必须指定</th>
<th>默认值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>value</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>主键字段名</td>
</tr>
<tr>
<td>type</td>
<td>Enum</td>
<td>否</td>
<td>IdType.NONE</td>
<td>主键类型</td>
</tr>
</tbody></table>
<h4 id="IdType"><a href="#IdType" class="headerlink" title="IdType"></a>IdType</h4><table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>AUTO</td>
<td>数据库ID自增</td>
</tr>
<tr>
<td>NONE</td>
<td>无状态,该类型为未设置主键类型(注解里等于跟随全局,全局里约等于 INPUT)</td>
</tr>
<tr>
<td>INPUT</td>
<td>insert前自行set主键值</td>
</tr>
<tr>
<td>ASSIGN_ID</td>
<td>分配ID(主键类型为Number(Long和Integer)或String)(since 3.3.0),使用接口<code>IdentifierGenerator</code>的方法<code>nextId</code>(默认实现类为<code>DefaultIdentifierGenerator</code>雪花算法)</td>
</tr>
<tr>
<td>ASSIGN_UUID</td>
<td>分配UUID,主键类型为String(since 3.3.0),使用接口<code>IdentifierGenerator</code>的方法<code>nextUUID</code>(默认default方法)</td>
</tr>
<tr>
<td>ID_WORKER</td>
<td>分布式全局唯一ID 长整型类型(please use <code>ASSIGN_ID</code>)</td>
</tr>
<tr>
<td>UUID</td>
<td>32位UUID字符串(please use <code>ASSIGN_UUID</code>)</td>
</tr>
<tr>
<td>ID_WORKER_STR</td>
<td>分布式全局唯一ID 字符串类型(please use <code>ASSIGN_ID</code>)</td>
</tr>
</tbody></table>
<h3 id="TableField"><a href="#TableField" class="headerlink" title="@TableField"></a>@TableField</h3><ul>
<li>描述：字段注解(非主键)</li>
</ul>
<table>
<thead>
<tr>
<th>属性</th>
<th>类型</th>
<th>必须指定</th>
<th>默认值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>value</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>字段名</td>
</tr>
<tr>
<td>el</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>映射为原生 <code>#{ ... }</code> 逻辑,相当于写在 xml 里的 <code>#{ ... }</code> 部分</td>
</tr>
<tr>
<td>exist</td>
<td>boolean</td>
<td>否</td>
<td>true</td>
<td>是否为数据库表字段</td>
</tr>
<tr>
<td>condition</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>字段 <code>where</code> 实体查询比较条件,有值设置则按设置的值为准,没有则为默认全局的 <code>%s=#{\%s}</code></td>
</tr>
<tr>
<td>update</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>字段 <code>update set</code> 部分注入, 例如：update=”%s+1”：表示更新时会set version=version+1(该属性优先级高于 <code>el</code> 属性)</td>
</tr>
<tr>
<td>insertStrategy</td>
<td>Enum</td>
<td>N</td>
<td>DEFAULT</td>
<td>举例：NOT_NULL: <code>insert into table_a(&lt;if test=&quot;columnProperty != null&quot;&gt;column&lt;/if&gt;) values (&lt;if test=&quot;columnProperty != null&quot;&gt;#{columnProperty}&lt;/if&gt;)</code></td>
</tr>
<tr>
<td>updateStrategy</td>
<td>Enum</td>
<td>N</td>
<td>DEFAULT</td>
<td>举例：IGNORED: <code>update table_a set column=#{columnProperty}</code></td>
</tr>
<tr>
<td>whereStrategy</td>
<td>Enum</td>
<td>N</td>
<td>DEFAULT</td>
<td>举例：NOT_EMPTY: <code>where &lt;if test=&quot;columnProperty != null and columnProperty!=&#39;&#39;&quot;&gt;column=#{columnProperty}&lt;/if&gt;</code></td>
</tr>
<tr>
<td>fill</td>
<td>Enum</td>
<td>否</td>
<td>FieldFill.DEFAULT</td>
<td>字段自动填充策略</td>
</tr>
<tr>
<td>select</td>
<td>boolean</td>
<td>否</td>
<td>true</td>
<td>是否进行 select 查询</td>
</tr>
<tr>
<td>keepGlobalFormat</td>
<td>boolean</td>
<td>否</td>
<td>false</td>
<td>是否保持使用全局的 format 进行处理</td>
</tr>
<tr>
<td>jdbcType</td>
<td>JdbcType</td>
<td>否</td>
<td>JdbcType.UNDEFINED</td>
<td>JDBC类型 (该默认值不代表会按照该值生效)</td>
</tr>
<tr>
<td>typeHandler</td>
<td>Class&lt;? extends TypeHandler&gt;</td>
<td>否</td>
<td>UnknownTypeHandler.class</td>
<td>类型处理器 (该默认值不代表会按照该值生效)</td>
</tr>
<tr>
<td>numericScale</td>
<td>String</td>
<td>否</td>
<td>“”</td>
<td>指定小数点后保留的位数</td>
</tr>
</tbody></table>
<p>关于<code>jdbcType</code>和<code>typeHandler</code>以及<code>numericScale</code>的说明:</p>
<p><code>numericScale</code>只生效于 update 的sql. <code>jdbcType</code>和<code>typeHandler</code>如果不配合<code>@TableName#autoResultMap = true</code>一起使用,也只生效于 update 的sql. 对于<code>typeHandler</code>如果你的字段类型和set进去的类型为<code>equals</code>关系,则只需要让你的<code>typeHandler</code>让Mybatis加载到即可,不需要使用注解</p>
<h4 id="FieldStrategy"><a href="#FieldStrategy" class="headerlink" title="FieldStrategy"></a>FieldStrategy</h4><table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>IGNORED</td>
<td>忽略判断</td>
</tr>
<tr>
<td>NOT_NULL</td>
<td>非NULL判断</td>
</tr>
<tr>
<td>NOT_EMPTY</td>
<td>非空判断(只对字符串类型字段,其他类型字段依然为非NULL判断)</td>
</tr>
<tr>
<td>DEFAULT</td>
<td>追随全局配置</td>
</tr>
</tbody></table>
<h4 id="FieldFill"><a href="#FieldFill" class="headerlink" title="FieldFill"></a>FieldFill</h4><table>
<thead>
<tr>
<th>值</th>
<th>描述</th>
</tr>
</thead>
<tbody><tr>
<td>DEFAULT</td>
<td>默认不处理</td>
</tr>
<tr>
<td>INSERT</td>
<td>插入时填充字段</td>
</tr>
<tr>
<td>UPDATE</td>
<td>更新时填充字段</td>
</tr>
<tr>
<td>INSERT_UPDATE</td>
<td>插入和更新时填充字段</td>
</tr>
</tbody></table>
<p>在更新时候遇到一个小发现</p>
<p>用Lambda方法进行更新时，用set()某个值不会进行自动填充，必须new一个新的对象才会进行自动填充update</p>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2021\05\06\springboot\jwt\" rel="bookmark">Spring Boot 实现 JWT</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2020\02\29\springboot\swagger2笔记\springboot整合swagger2生成apidoc\" rel="bookmark">springboot整合swagger2</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2018\09\03\springboot\web笔记\(转)Controller接收参数的几种常用方式\" rel="bookmark">(转)Controller接收参数的几种常用方式</a></div>
    </li>
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2018\09\04\springboot\web笔记\(转)注解-CrossOrigin解决跨域问题\" rel="bookmark">(转)注解@CrossOrigin解决跨域问题</a></div>
    </li>
  </ul>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Zlatanlong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://lclong.top/2020/03/17/springboot/mybatis-plus%E7%AC%94%E8%AE%B0/mybatis-plus/" title="Mybatis Plus的使用">https://lclong.top/2020/03/17/springboot/mybatis-plus笔记/mybatis-plus/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/Spring-Boot/" rel="tag"><i class="fa fa-tag"></i> Spring Boot</a>
              <a href="/tags/Mybatis-Plus/" rel="tag"><i class="fa fa-tag"></i> Mybatis Plus</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/03/17/Git%E4%B8%8EGit%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4/" rel="prev" title="Git与Git相关命令">
      <i class="fa fa-chevron-left"></i> Git与Git相关命令
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/04/11/Java/Java%E4%B8%AD%E4%BC%A0%E9%80%92%E5%87%BD%E6%95%B0(%E8%A1%8C%E4%B8%BA)%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F/" rel="next" title="Java中传递函数(行为)的两种方式">
      Java中传递函数(行为)的两种方式 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  
  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Mybatis-Plus"><span class="nav-number">1.</span> <span class="nav-text">Mybatis Plus</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#基本结构："><span class="nav-number">1.1.</span> <span class="nav-text">基本结构：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#配置基本："><span class="nav-number">1.2.</span> <span class="nav-text">配置基本：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#导入依赖："><span class="nav-number">1.2.1.</span> <span class="nav-text">导入依赖：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#application-yml"><span class="nav-number">1.2.2.</span> <span class="nav-text">application.yml</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#添加扫描路径："><span class="nav-number">1.2.3.</span> <span class="nav-text">添加扫描路径：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#基本方法："><span class="nav-number">1.3.</span> <span class="nav-text">基本方法：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#用户实体："><span class="nav-number">1.3.1.</span> <span class="nav-text">用户实体：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编写Mapper类，并集成BaseMapper"><span class="nav-number">1.3.2.</span> <span class="nav-text">编写Mapper类，并集成BaseMapper</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常用注解"><span class="nav-number">1.4.</span> <span class="nav-text">常用注解</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#TableName"><span class="nav-number">1.4.1.</span> <span class="nav-text">@TableName</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TableId"><span class="nav-number">1.4.2.</span> <span class="nav-text">@TableId</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#IdType"><span class="nav-number">1.4.2.1.</span> <span class="nav-text">IdType</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#TableField"><span class="nav-number">1.4.3.</span> <span class="nav-text">@TableField</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#FieldStrategy"><span class="nav-number">1.4.3.1.</span> <span class="nav-text">FieldStrategy</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#FieldFill"><span class="nav-number">1.4.3.2.</span> <span class="nav-text">FieldFill</span></a></li></ol></li></ol></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Zlatanlong"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Zlatanlong</p>
  <div class="site-description" itemprop="description">生活就像巧克力🍫</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3psYXRhbmxvbmc=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zlatanlong"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxvbmctdHhnY0Bmb3htYWlsLmNvbQ==" title="E-Mail → mailto:long-txgc@foxmail.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      关注列表
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9sZWZsYWNvbi5naXRodWIuaW8v" title="https:&#x2F;&#x2F;leflacon.github.io&#x2F;">leflacon</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9ib2Jib3NzLmdpdGh1Yi5pby8=" title="https:&#x2F;&#x2F;bobboss.github.io&#x2F;">BobBoss</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cDovL29wdGltaXN0aWNhdC54eXovdXNlcj91c2VySWQ9bHpkY2w=" title="http:&#x2F;&#x2F;optimisticat.xyz&#x2F;user?userId&#x3D;lzdcl">lzdcl</span>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zlatanlong</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">166k</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> v7.7.1
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@latest/canvas-nest-nomobile.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'H5inyassVpcpItLTuMJH9aBg-gzGzoHsz',
      appKey     : 'mBzB6QB3deD6zw8YEIKVQdzz',
      placeholder: "快来说两句吧。。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
